#ifndef _UBT_PROTO_ADJUST_H_
#define _UBT_PROTO_ADJUST_H_
#include <string>
#include "geometry_msgs/Pose2D.h"

namespace ubt_proto_adjust
{
/*
	客户端发送请求start,stop,pause,continue,query;服务端收到后，发送相应应答.
	服务端发送状态上报status_nty,其中status<=0的为完成类上报
	服务端启动后，应立即发送一次status_nty(taskId为空)
*/
enum ubt_adjust_msg_type
{
    ubt_adjust_msg_type_start_req = 1,	//开始请求,data为ubt_adjust_msg_start_req
    ubt_adjust_msg_type_start_rsp = 0x81, //开始回应,data为ubt_adjust_msg_com_rsp

    ubt_adjust_msg_type_stop_req = 2,	//结束请求,data为ubt_adjust_msg_stop_req
    ubt_adjust_msg_type_stop_rsp = 0x82,	//结束回应,data为ubt_adjust_msg_com_rsp

    ubt_adjust_msg_type_pause_req = 3,	//暂停请求,data为空
    ubt_adjust_msg_type_pause_rsp = 0x83, //暂停回应,data为ubt_adjust_msg_com_rsp

    ubt_adjust_msg_type_continue_req = 4, //继续请求,data为空
    ubt_adjust_msg_type_continue_rsp = 0x84, //继续回应,data为ubt_adjust_msg_com_rsp

    ubt_adjust_msg_type_query_req = 5,	 //查询请求,data为空
    ubt_adjust_msg_type_query_rsp = 0x85, //查询回应,data为data为ubt_adjust_status

    ubt_adjust_msg_type_status_nty = 0x80 //状态上报,data为data为ubt_adjust_status
};

enum ubt_adjust_pose_type
{
    ubt_adjust_pose_odomrel = 1, //相对(于当前)里程计
    ubt_adjust_pose_odom = 2,	//里程计
    ubt_adjust_pose_map = 3,	//地图
    ubt_adjust_pose_rack = 4,	//货架
    ubt_adjust_pose_qrcode = 5,	//下方二维码
    ubt_adjust_pose_qrcode1 = 6,  //上方二维码
};

typedef struct
{
    int result;//>=0成功， <0失败, 见ubt_adjust_result
    std::string desc;
} ubt_adjust_msg_com_rsp;

enum ubt_adjust_result
{
    ubt_adjust_result_failbase = -100, //各接口单独定义失败值的基准
    ubt_adjust_result_ok = 0, //成功
    ubt_adjust_result_okbase = 100, //各接口单独定义成功值的基准
};

typedef struct
{
    std::string taskId;//任务Id
    int lifeTime;	//有效期,单位秒,=0时不限定,否则 消息时间(为0取接收到的时间)+lifeTime为任务截止时间(默认为0)
    ubt_adjust_pose_type poseType;//目标位姿类型(默认odom)
    geometry_msgs::Pose2D  poseDst;//目标位姿(默认x为 0,y 为0,theta为0)
    geometry_msgs::Pose2D  poseLmt;//允许的偏差最大值(各分量独立判断,必须都小于等于最大值才行,
    //基于目标位姿的坐标系,即x轴为目标位姿起,沿其theta角度所指射线(默认值与poseType相关)
    int isPause;	//初始状态是否为暂停，默认0
} ubt_adjust_msg_start_req;

enum ubt_adjust_theta
{
    ubt_adjust_theta_4x90 = 10, //4个直角,即0,pi/2,pi,-pi/2
    ubt_adjust_theta_2x180 = 11, //2个平角,即0,pi
};

typedef struct
{
    int iCleanInfo;//是否清除任务信息,0不清除，1清除(默认0)
    int duration;//多久内停止下来，单位秒，为0时立即停止(默认0)
    int runStatus;//停止后的runStatus,取值在(ubt_adjust_run_status_failbase,0) (默认cancel)
} ubt_adjust_msg_stop_req;

typedef struct
{
    std::string taskId;//来自start_req.taskId
    int ttl;	 //当前距任务截止时间的秒数
    int runStatus; //运行状态,0为 正常完成,<0 为失败完成, >0为中间状态(完成类状态，允许start新任务)
    int flag;//标志
    std::string runDesc;//运行描述
    int isPoseOffVirtual;//偏移是否虚拟的
    geometry_msgs::Pose2D  poseOff;//距离目标位姿的偏移
} ubt_adjust_status;
#define ubt_adjust_flag_stopping  0x01    //是否停止中
#define ubt_adjust_flag_pause 0x02	//是否暂停中

enum ubt_adjust_run_status
{
    ubt_adjust_run_status_done = 0,	//成功完成
    ubt_adjust_run_status_cancel = -1,
    ubt_adjust_run_status_stopbtn = -2,
    ubt_adjust_run_status_nrfault = -3,
    ubt_adjust_run_status_timeout = -4,
    ubt_adjust_run_status_failbase = -100, //自定义失败完成的基准值,
};

int ubtAdjustEncodeComRsp(std::string&  buf, ubt_adjust_msg_com_rsp *pComRsp, std::string& failDesc);
int ubtAdjustEncodeStartReq(std::string&  buf, ubt_adjust_msg_start_req *pStartReq, std::string& failDesc);
int ubtAdjustEncodeStopReq(std::string&  buf, ubt_adjust_msg_stop_req *pStopReq, std::string& failDesc);
int ubtAdjustEncodeStatus(std::string&  buf, ubt_adjust_status *pStatus, std::string& failDesc);

int ubtAdjustDecodeComRsp(std::string& buf, ubt_adjust_msg_com_rsp *pComRsp, std::string& failDesc);
int ubtAdjustDecodeStartReq(std::string& buf, ubt_adjust_msg_start_req *pStartReq, std::string& failDesc);
int ubtAdjustDecodeStopReq(std::string&  buf, ubt_adjust_msg_stop_req *pStopReq, std::string& failDesc);
int ubtAdjustDecodeStatus(std::string& buf, ubt_adjust_status *pStatus, std::string& failDesc);

}
#endif

